<?php

// Define path to application directory
defined('APPLICATION_PATH')
        || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

// Define application environment
defined('APPLICATION_ENV')
        || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
            realpath(APPLICATION_PATH . '/../library'),
            'C:\ZendFramework-1.12.0\library',
            get_include_path(),
        )));

/** Zend_Application */
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
                APPLICATION_ENV,
                APPLICATION_PATH . '/configs/application.ini'
);

// define application options and read params from CLI
$getopt = new Zend_Console_Getopt(array(
            'action|a=s' => 'action',
            'controller|c=s' => 'controller',
            'params|p=s' => 'params as url string',
        ));

try {
    $getopt->parse();
} catch (Zend_Console_Getopt_Exception $e) {
    // Bad options passed: report usage
    echo $e->getUsageMessage();
    return false;
}
//array('frontController', 'db', 'mail')

$application = new Zend_Application(
                APPLICATION_ENV,
                APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap();

$front = $application->getBootstrap()->getResource('FrontController');
$params = array();
parse_str($getopt->p, $params);

$request = new Zend_Controller_Request_Simple(
                empty($getopt->a) ? 'index' : $getopt->a,
                empty($getopt->c) ? 'index' : $getopt->c,
                'cron',
                $params
);
$front->setRequest($request)
        ->setRouter(new Common_Controller_Router_Cli())
        ->setResponse(new Zend_Controller_Response_Cli());

$logger = Zend_Registry::get('logger');
$logger->log("message", Zend_Log::INFO);

$application->run();

